/*  
     PlAr is Platform Arena: a 2D multiplayer shooting game
     Copyright (C) 2009 Ragagnin Antonio <spocchio@gmail.com>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package plar.core;

import java.util.HashMap;

public class ActionManager {

	public HashMap<String, Action> actions;

	public ActionManager() {
		actions = new HashMap<String, Action>();
	}

	public Action addAction(String name, Action a) {
		if (actions.containsKey(name))
			stopAction(name);
		actions.put(name, a);
		return a;
	}

	public Action getAction(String s) {
		return actions.get(s);
	}

	public boolean hasAction(String string) {
		return actions.containsKey(string);
	}

	public void removeAction(String s) {
		actions.remove(s);

	}

	public void removeAction(String s, Action a) {
		actions.remove(s);
	}

	public Parameters runAction(String s, Parameters p) {
		p.put("actionManager", this);
		p.put("actionName", s);
		return actions.get(s).call(p);
	}

	public void runAll(Parameters info) {
		// Common.info("exec start---");
		for (String s : actions.keySet()) {
			// Common.info("exec: "+s);
			Parameters i = new Parameters(info);
			runAction(s, i);
		}
		// Common.info("exec ---");
	}

	private void stopAction(String name) {

	}

}
